package com.example.calendar

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.navigation.compose.rememberNavController
import com.example.calendar.ui.CalendarNavHost
import com.example.calendar.ui.components.CalendarBottomBar
import com.example.calendar.ui.components.CalendarTopBar
import com.example.calendar.ui.theme.CalendarTheme
import dagger.hilt.android.AndroidEntryPoint

/**
 * Main activity for the Calendar application.
 * Hosts the Compose UI and navigation components.
 */
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            CalendarTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    val navController = rememberNavController()
                    var currentRoute by remember { mutableStateOf("month") }
                    
                    Scaffold(
                        topBar = {
                            CalendarTopBar(
                                title = "Calendar",
                                showMenuButton = true,
                                showMoreOptions = true
                            )
                        },
                        bottomBar = {
                            CalendarBottomBar(
                                currentRoute = currentRoute,
                                onNavigate = { route ->
                                    navController.navigate(route) {
                                        // Pop up to the start destination of the graph to
                                        // avoid building up a large stack of destinations
                                        popUpTo(navController.graph.startDestinationId) {
                                            saveState = true
                                        }
                                        // Avoid multiple copies of the same destination when
                                        // reselecting the same item
                                        launchSingleTop = true
                                        // Restore state when reselecting a previously selected item
                                        restoreState = true
                                    }
                                    currentRoute = route
                                }
                            )
                        }
                    ) { innerPadding ->
                        CalendarNavHost(
                            navController = navController,
                            modifier = Modifier.padding(innerPadding),
                            onRouteChange = { route ->
                                currentRoute = route
                            }
                        )
                    }
                }
            }
        }
    }
} 